using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class Map : MonoBehaviour
{
    private GameObject panelLock;
    private GameObject star;
    private TextMeshProUGUI textStar;
    private int id;

    void Awake()
    {
        this.panelLock = transform.Find("LockPanel").gameObject;
        this.star = transform.Find("Star").gameObject;
        this.textStar = this.star.GetComponentInChildren<TextMeshProUGUI>();

        this.panelLock.SetActive(true);
        this.star.SetActive(false);
    }

    /// <summary>
    /// 显示地图入口
    /// </summary>
    /// <param name="id">地图ID，从0开始</param>
    /// <param name="starCount">获得的星星数量</param>
    public void Show(int id, int starCount)
    {
        this.id = id;

        if (starCount >= 0)
        {
            this.panelLock.SetActive(false);
            gameObject.AddComponent<Button>().onClick.AddListener(this.OnClick);
        }

        if (starCount > 0)
        {
            this.star.SetActive(true);
            this.textStar.text = starCount.ToString();
        }
    }
    
    public void OnClick()
    {
        LevelManager.Instance.LoadLevels(this.id);
    }
}
